<template>
  <div class="login-form">
    <div class="login-logo">
      <img src="@/assets/fuzhi.svg" alt="" />
    </div>
    <el-form ref="loginForm" :model="loginForm" :rules="rules" label-width="0px">
      <el-form-item prop="username">
        <el-input v-model="loginForm.username" placeholder="请输入用户名"></el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input type="password" v-model="loginForm.password" placeholder="请输入密码"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button style="width: 100%" type="primary" @click="handleSubmit">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  emits: ["login"],
  data() {
    return {
      loginForm: {
        username: "",
        password: ""
      },
      rules: {
        username: [{ required: true, message: "请输入用户名", trigger: "blur" }],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }]
      }
    };
  },
  methods: {
    handleSubmit() {
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          // 处理登录逻辑，例如提交表单数据到后端
          console.log("登录成功");
          this.$emit("login", this.loginForm);
        } else {
          // 表单验证不通过的处理
          console.log("登录失败，请检查输入");
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.login-form {
  width: 400px;
  margin: auto;
  padding: 20px 20px 2px;
  border-radius: 5px;
  backdrop-filter: blur(2px);
  .login-logo {
    width: 80px;
    height: 80px;
    margin: 0 auto 20px;
    img {
      width: 100%;
      height: 100%;
      display: block;
    }
  }
}
</style>
